package ml.coursedesign.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ml.coursedesign.entity.GroupVo;
import ml.coursedesign.entity.SelectSubject;
import ml.coursedesign.entity.SubjectInfoVO;
import ml.coursedesign.mapper.SelectSubjectMapper;
import ml.coursedesign.service.SelectSubjectService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SelectSubjectServiceImpl extends ServiceImpl<SelectSubjectMapper, SelectSubject> implements SelectSubjectService {


    @Override
    public List<SelectSubject> getGroupfoList(String subjectid, String classId) {
        QueryWrapper<SelectSubject> queryWrapper = new QueryWrapper();
        queryWrapper.eq("subject_id",subjectid);
        queryWrapper.eq("course_class_id",classId);
        List<SelectSubject> selectSubjects = baseMapper.selectList(queryWrapper);
        return selectSubjects;

    }

    @Override
    public List<SubjectInfoVO> getSubjectInfoVOList(SubjectInfoVO subjectInfoVO) {
        String stubjectId = changNullInputStr(subjectInfoVO.getSubjectId());
        String stubjectName = changNullInputStr(subjectInfoVO.getSubjectName());
        String groupLeaderName = changNullInputStr(subjectInfoVO.getGroupLeaderName());
        String courseClassId = changNullInputStr(subjectInfoVO.getCourseClassId());
        System.err.println("courseClassId"+courseClassId);

        List<SubjectInfoVO> subjectInfoVOList= baseMapper.getSubjectInfoVOList(stubjectId,stubjectName,groupLeaderName,courseClassId);
        return subjectInfoVOList;
    }

    @Override
    public int getseletedCountNum(String sujectId,String className) {
        String classId = String.valueOf(className.charAt(className.length()-2) );
        QueryWrapper<SelectSubject> subjectQueryWrapper = new QueryWrapper<>();
        subjectQueryWrapper.eq("subject_id",sujectId);
        subjectQueryWrapper.eq("course_class_id",classId);
        List<SelectSubject> selectSubjects = baseMapper.selectList(subjectQueryWrapper);
        return selectSubjects.size() ;
    }




    private String changNullInputStr(String str){
        if(str ==null){
            return "";
        }
        return str;
    }


}
